log using messaging-replicate.txt, t replace

use messaging, clear

sort ResponseId

/*label variables*/

label variable Q2_1 "Zip Code"
label variable Q3 "Registered to vote, 1=No, 2=Yes"
label variable Q4 "Party registration"
label variable Q5 "Ideological self-description"
label variable Q6 "Partisan lean"
label variable Q7 "Household income"
label variable Q8 "Homeownership"
label variable Q9 "Age"
label variable Q10 "Sex"
label variable Q11 "Education"
label variable Q31 "Messaging prompt"
label variable Q31_1 "Failed attention check"
label variable Q34 "Reduce regulation"
label variable Q35 "Affordable housing"
label variable Q36 "Prevent development"
label variable Q37 "Hard limit for permits"
replace Q31_1=0 if missing(Q31_1)

label list

*Rescale prompt to make control base category

gen prompt=.
replace prompt = 0 if Q31 == 2
replace prompt = 1 if Q31 == 1
replace prompt = 2 if Q31 == 4
replace prompt = 3 if Q31 == 3
label define prompt 0 "Control" 1 "Economic expertise" 2 "Property rights" 3 "Fairness"

*Rescale Likert scales

gen reducereg = .
replace reducereg = -2 if Q34 == 5
replace reducereg = -1 if Q34 == 2
replace reducereg = 0 if Q34 == 3
replace reducereg = 1 if Q34 == 1
replace reducereg = 2 if Q34 == 4
gen affordable = .
replace affordable = -2 if Q35 == 5
replace affordable = -1 if Q35 == 2
replace affordable = 0 if Q35 == 3
replace affordable = 1 if Q35 == 1
replace affordable = 2 if Q35 == 4
gen preventdev = .
replace preventdev = -2 if Q36 == 5
replace preventdev = -1 if Q36 == 2
replace preventdev = 0 if Q36 == 3
replace preventdev = 1 if Q36 == 1
replace preventdev = 2 if Q36 == 4
gen hardlimit = .
replace hardlimit = -2 if Q37 == 5
replace hardlimit = -1 if Q37 == 2
replace hardlimit = 0 if Q37 == 3
replace hardlimit = 1 if Q37 == 1
replace hardlimit = 2 if Q37 == 4

*summary stats for control prompt & reg voters
tab reducereg if prompt==0 & Q3==2
tab affordable if prompt==0 & Q3==2
tab preventdev if prompt==0 & Q3==2
tab hardlimit if prompt==0 & Q3==2
tab Q4 if prompt==0 & Q3==2
tab Q10 if prompt==0 & Q3==2
tab Q9  if prompt==0 & Q3==2
tab Q8  if prompt==0 & Q3==2

drop Q31 Q34-Q37

order ResponseId Q2_1 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 prompt reducereg affordable preventdev hardlimit Q31_1

*prompt does not predict inattentiveness
reg Q31_1 i.prompt

*generate fips variable in survey 
gen fips = .
label var fips "County FIPS code"

*Assign counties to zip codes
*New Hampshire
decode Q2_1, gen(q2)
replace fips = 	33001	if q2 == "03218"
replace fips = 	33001	if q2 == "03220"
replace fips = 	33001	if q2 == "03225"
replace fips = 	33001	if q2 == "03226"
replace fips = 	33001	if q2 == "03237"
replace fips = 	33001	if q2 == "03246"
replace fips = 	33001	if q2 == "03247"
replace fips = 	33001	if q2 == "03249"
replace fips = 	33001	if q2 == "03252"
replace fips = 	33001	if q2 == "03253"
replace fips = 	33001	if q2 == "03256"
replace fips = 	33001	if q2 == "03269"
replace fips = 	33001	if q2 == "03289"
replace fips = 	33001	if q2 == "03298"
replace fips = 	33001	if q2 == "03299"
replace fips = 	33001	if q2 == "03809"
replace fips = 	33001	if q2 == "03810"
replace fips = 	33001	if q2 == "03837"
replace fips = 	33003	if q2 == "03227"
replace fips = 	33003	if q2 == "03254"
replace fips = 	33003	if q2 == "03259"
replace fips = 	33003	if q2 == "03812"
replace fips = 	33003	if q2 == "03813"
replace fips = 	33003	if q2 == "03814"
replace fips = 	33003	if q2 == "03816"
replace fips = 	33003	if q2 == "03817"
replace fips = 	33003	if q2 == "03818"
replace fips = 	33003	if q2 == "03830"
replace fips = 	33003	if q2 == "03832"
replace fips = 	33003	if q2 == "03836"
replace fips = 	33003	if q2 == "03838"
replace fips = 	33003	if q2 == "03845"
replace fips = 	33003	if q2 == "03846"
replace fips = 	33003	if q2 == "03847"
replace fips = 	33003	if q2 == "03849"
replace fips = 	33003	if q2 == "03850"
replace fips = 	33003	if q2 == "03853"
replace fips = 	33003	if q2 == "03860"
replace fips = 	33003	if q2 == "03864"
replace fips = 	33003	if q2 == "03872"
replace fips = 	33003	if q2 == "03875"
replace fips = 	33003	if q2 == "03882"
replace fips = 	33003	if q2 == "03883"
replace fips = 	33003	if q2 == "03886"
replace fips = 	33003	if q2 == "03890"
replace fips = 	33003	if q2 == "03894"
replace fips = 	33003	if q2 == "03896"
replace fips = 	33003	if q2 == "03897"
replace fips = 	33005	if q2 == "03431"
replace fips = 	33005	if q2 == "03435"
replace fips = 	33005	if q2 == "03441"
replace fips = 	33005	if q2 == "03443"
replace fips = 	33005	if q2 == "03444"
replace fips = 	33005	if q2 == "03445"
replace fips = 	33005	if q2 == "03446"
replace fips = 	33005	if q2 == "03447"
replace fips = 	33005	if q2 == "03448"
replace fips = 	33005	if q2 == "03450"
replace fips = 	33005	if q2 == "03451"
replace fips = 	33005	if q2 == "03452"
replace fips = 	33005	if q2 == "03455"
replace fips = 	33005	if q2 == "03456"
replace fips = 	33005	if q2 == "03457"
replace fips = 	33005	if q2 == "03461"
replace fips = 	33005	if q2 == "03462"
replace fips = 	33005	if q2 == "03464"
replace fips = 	33005	if q2 == "03465"
replace fips = 	33005	if q2 == "03466"
replace fips = 	33005	if q2 == "03467"
replace fips = 	33005	if q2 == "03469"
replace fips = 	33005	if q2 == "03470"
replace fips = 	33005	if q2 == "03602"
replace fips = 	33005	if q2 == "03604"
replace fips = 	33005	if q2 == "03608"
replace fips = 	33005	if q2 == "03609"
replace fips = 	33007	if q2 == "03570"
replace fips = 	33007	if q2 == "03575"
replace fips = 	33007	if q2 == "03576"
replace fips = 	33007	if q2 == "03579"
replace fips = 	33007	if q2 == "03581"
replace fips = 	33007	if q2 == "03582"
replace fips = 	33007	if q2 == "03583"
replace fips = 	33007	if q2 == "03584"
replace fips = 	33007	if q2 == "03588"
replace fips = 	33007	if q2 == "03589"
replace fips = 	33007	if q2 == "03590"
replace fips = 	33007	if q2 == "03592"
replace fips = 	33007	if q2 == "03593"
replace fips = 	33007	if q2 == "03595"
replace fips = 	33007	if q2 == "03597"
replace fips = 	33007	if q2 == "03598"
replace fips = 	33009	if q2 == "03215"
replace fips = 	33009	if q2 == "03217"
replace fips = 	33009	if q2 == "03222"
replace fips = 	33009	if q2 == "03223"
replace fips = 	33009	if q2 == "03238"
replace fips = 	33009	if q2 == "03240"
replace fips = 	33009	if q2 == "03241"
replace fips = 	33009	if q2 == "03245"
replace fips = 	33009	if q2 == "03251"
replace fips = 	33009	if q2 == "03262"
replace fips = 	33009	if q2 == "03264"
replace fips = 	33009	if q2 == "03266"
replace fips = 	33009	if q2 == "03274"
replace fips = 	33009	if q2 == "03279"
replace fips = 	33009	if q2 == "03282"
replace fips = 	33009	if q2 == "03285"
replace fips = 	33009	if q2 == "03293"
replace fips = 	33009	if q2 == "03561"
replace fips = 	33009	if q2 == "03574"
replace fips = 	33009	if q2 == "03580"
replace fips = 	33009	if q2 == "03585"
replace fips = 	33009	if q2 == "03586"
replace fips = 	33009	if q2 == "03740"
replace fips = 	33009	if q2 == "03741"
replace fips = 	33009	if q2 == "03748"
replace fips = 	33009	if q2 == "03749"
replace fips = 	33009	if q2 == "03750"
replace fips = 	33009	if q2 == "03755"
replace fips = 	33009	if q2 == "03756"
replace fips = 	33009	if q2 == "03765"
replace fips = 	33009	if q2 == "03766"
replace fips = 	33009	if q2 == "03768"
replace fips = 	33009	if q2 == "03769"
replace fips = 	33009	if q2 == "03771"
replace fips = 	33009	if q2 == "03774"
replace fips = 	33009	if q2 == "03777"
replace fips = 	33009	if q2 == "03779"
replace fips = 	33009	if q2 == "03780"
replace fips = 	33009	if q2 == "03784"
replace fips = 	33009	if q2 == "03785"
replace fips = 	33011	if q2 == "03031"
replace fips = 	33011	if q2 == "03033"
replace fips = 	33011	if q2 == "03043"
replace fips = 	33011	if q2 == "03045"
replace fips = 	33011	if q2 == "03047"
replace fips = 	33011	if q2 == "03048"
replace fips = 	33011	if q2 == "03049"
replace fips = 	33011	if q2 == "03051"
replace fips = 	33011	if q2 == "03052"
replace fips = 	33011	if q2 == "03054"
replace fips = 	33011	if q2 == "03055"
replace fips = 	33011	if q2 == "03057"
replace fips = 	33011	if q2 == "03060"
replace fips = 	33011	if q2 == "03061"
replace fips = 	33011	if q2 == "03062"
replace fips = 	33011	if q2 == "03063"
replace fips = 	33011	if q2 == "03064"
replace fips = 	33011	if q2 == "03070"
replace fips = 	33011	if q2 == "03071"
replace fips = 	33011	if q2 == "03076"
replace fips = 	33011	if q2 == "03082"
replace fips = 	33011	if q2 == "03084"
replace fips = 	33011	if q2 == "03086"
replace fips = 	33011	if q2 == "03101"
replace fips = 	33011	if q2 == "03102"
replace fips = 	33011	if q2 == "03103"
replace fips = 	33011	if q2 == "03104"
replace fips = 	33011	if q2 == "03105"
replace fips = 	33011	if q2 == "03107"
replace fips = 	33011	if q2 == "03108"
replace fips = 	33011	if q2 == "03109"
replace fips = 	33011	if q2 == "03110"
replace fips = 	33011	if q2 == "03111"
replace fips = 	33011	if q2 == "03244"
replace fips = 	33011	if q2 == "03281"
replace fips = 	33011	if q2 == "03440"
replace fips = 	33011	if q2 == "03442"
replace fips = 	33011	if q2 == "03449"
replace fips = 	33011	if q2 == "03458"
replace fips = 	33011	if q2 == "03468"
replace fips = 	33013	if q2 == "03046"
replace fips = 	33013	if q2 == "03106"
replace fips = 	33013	if q2 == "03216"
replace fips = 	33013	if q2 == "03221"
replace fips = 	33013	if q2 == "03224"
replace fips = 	33013	if q2 == "03229"
replace fips = 	33013	if q2 == "03230"
replace fips = 	33013	if q2 == "03231"
replace fips = 	33013	if q2 == "03233"
replace fips = 	33013	if q2 == "03234"
replace fips = 	33013	if q2 == "03235"
replace fips = 	33013	if q2 == "03242"
replace fips = 	33013	if q2 == "03243"
replace fips = 	33013	if q2 == "03255"
replace fips = 	33013	if q2 == "03257"
replace fips = 	33013	if q2 == "03258"
replace fips = 	33013	if q2 == "03260"
replace fips = 	33013	if q2 == "03263"
replace fips = 	33013	if q2 == "03268"
replace fips = 	33013	if q2 == "03272"
replace fips = 	33013	if q2 == "03273"
replace fips = 	33013	if q2 == "03275"
replace fips = 	33013	if q2 == "03276"
replace fips = 	33013	if q2 == "03278"
replace fips = 	33013	if q2 == "03287"
replace fips = 	33013	if q2 == "03301"
replace fips = 	33013	if q2 == "03302"
replace fips = 	33013	if q2 == "03303"
replace fips = 	33013	if q2 == "03304"
replace fips = 	33013	if q2 == "03305"
replace fips = 	33013	if q2 == "03307"
replace fips = 	33015	if q2 == "03032"
replace fips = 	33015	if q2 == "03034"
replace fips = 	33015	if q2 == "03036"
replace fips = 	33015	if q2 == "03037"
replace fips = 	33015	if q2 == "03038"
replace fips = 	33015	if q2 == "03040"
replace fips = 	33015	if q2 == "03041"
replace fips = 	33015	if q2 == "03042"
replace fips = 	33015	if q2 == "03044"
replace fips = 	33015	if q2 == "03053"
replace fips = 	33015	if q2 == "03073"
replace fips = 	33015	if q2 == "03077"
replace fips = 	33015	if q2 == "03079"
replace fips = 	33015	if q2 == "03087"
replace fips = 	33015	if q2 == "03261"
replace fips = 	33015	if q2 == "03290"
replace fips = 	33015	if q2 == "03291"
replace fips = 	33015	if q2 == "03801"
replace fips = 	33015	if q2 == "03802"
replace fips = 	33015	if q2 == "03803"
replace fips = 	33015	if q2 == "03804"
replace fips = 	33015	if q2 == "03805"
replace fips = 	33015	if q2 == "03811"
replace fips = 	33015	if q2 == "03819"
replace fips = 	33015	if q2 == "03826"
replace fips = 	33015	if q2 == "03827"
replace fips = 	33015	if q2 == "03833"
replace fips = 	33015	if q2 == "03840"
replace fips = 	33015	if q2 == "03841"
replace fips = 	33015	if q2 == "03842"
replace fips = 	33015	if q2 == "03843"
replace fips = 	33015	if q2 == "03844"
replace fips = 	33015	if q2 == "03848"
replace fips = 	33015	if q2 == "03854"
replace fips = 	33015	if q2 == "03856"
replace fips = 	33015	if q2 == "03857"
replace fips = 	33015	if q2 == "03858"
replace fips = 	33015	if q2 == "03859"
replace fips = 	33015	if q2 == "03862"
replace fips = 	33015	if q2 == "03865"
replace fips = 	33015	if q2 == "03870"
replace fips = 	33015	if q2 == "03871"
replace fips = 	33015	if q2 == "03873"
replace fips = 	33015	if q2 == "03874"
replace fips = 	33015	if q2 == "03885"
replace fips = 	33017	if q2 == "03815"
replace fips = 	33017	if q2 == "03820"
replace fips = 	33017	if q2 == "03821"
replace fips = 	33017	if q2 == "03822"
replace fips = 	33017	if q2 == "03823"
replace fips = 	33017	if q2 == "03824"
replace fips = 	33017	if q2 == "03825"
replace fips = 	33017	if q2 == "03835"
replace fips = 	33017	if q2 == "03839"
replace fips = 	33017	if q2 == "03851"
replace fips = 	33017	if q2 == "03852"
replace fips = 	33017	if q2 == "03855"
replace fips = 	33017	if q2 == "03861"
replace fips = 	33017	if q2 == "03866"
replace fips = 	33017	if q2 == "03867"
replace fips = 	33017	if q2 == "03868"
replace fips = 	33017	if q2 == "03869"
replace fips = 	33017	if q2 == "03878"
replace fips = 	33017	if q2 == "03884"
replace fips = 	33017	if q2 == "03887"
replace fips = 	33019	if q2 == "03280"
replace fips = 	33019	if q2 == "03284"
replace fips = 	33019	if q2 == "03601"
replace fips = 	33019	if q2 == "03603"
replace fips = 	33019	if q2 == "03605"
replace fips = 	33019	if q2 == "03607"
replace fips = 	33019	if q2 == "03743"
replace fips = 	33019	if q2 == "03745"
replace fips = 	33019	if q2 == "03746"
replace fips = 	33019	if q2 == "03751"
replace fips = 	33019	if q2 == "03752"
replace fips = 	33019	if q2 == "03753"
replace fips = 	33019	if q2 == "03754"
replace fips = 	33019	if q2 == "03770"
replace fips = 	33019	if q2 == "03773"
replace fips = 	33019	if q2 == "03781"
replace fips = 	33019	if q2 == "03782"

count if fips == .

order fips Q2_1

*Merge ACS and Voting data for weighted analysis here:
merge m:1 fips using "ACSDP5Y1Y_2018_DP0205_MRM052220.dta", generate(_mergeACS)
*56 not matched, these are the ones with bad zip entry and missing fips
sort ResponseId
merge m:1 fips using "04012020NHVoterRegistrationCounty.dta", generate(_mergeReg)
*56 not matched, these are the ones with bad zip entry and missing fips
sort ResponseId
drop _merge*

*generating dependent variable
paran reducereg affordable preventdev hardlimit, graph saving(pca.gph) replace seed(823408)
*produce Table 3
pca reducereg-hardlimit, comp(1)
esttab using msgtabs.tex, tex replace
predict component
label variable component "Pro-Housing Attitudes"
sort prompt
by prompt: sum component
sort ResponseId

*tables of summary statistics & correlations
estpost tab reducereg prompt
estpost tab affordable prompt
estpost tab preventdev prompt
estpost tab hardlimit prompt
estpost corr reducereg affordable preventdev hardlimit

**************************************************************************
**************************************************************************
*ESTIMATION
*create interactions

xi i.prompt i.Q6 i.Q5, noomit
label variable _Iprompt_1 "Economic expertise"
label variable _Iprompt_2 "Property rights"
label variable _Iprompt_3 "Fairness"

*unweighted estimates
*Produce Table 4, model (1)
reg component _Iprompt_1-_Iprompt_3, vce(robust)
est store Preu

*individual questions
*Produce Table 5
reg reducereg _Iprompt_1-_Iprompt_3 , vce(robust)
est store Q1_u
reg affordable _Iprompt_1-_Iprompt_3 , vce(robust)
est store Q2_u
reg preventdev _Iprompt_1-_Iprompt_3 , vce(robust)
est store Q3_u
reg hardlimit _Iprompt_1-_Iprompt_3 , vce(robust)
est store Q4_u

esttab Q1_u Q2_u Q3_u Q4_u using appendtabs.tex, replace se title("Messaging Effects: Individual Questions") ///
addnotes("All estimates use robust standard errors" ///
"Dependent variable - Likert scale" ///
"Unweighted observations") ///
star (* 0.10 ** 0.05 *** 0.01) tex mtitles("Reduce reg" "Affordable" "Prevent dev" "Hard limit") stats(N, label("Observations")) ///
label onecell 

*Heckman selection models
*Produce Appendix Table 5
xi i.Q11 i.Q7 i.prompt i.Q5 i.Q6, noomit
heckman component _Iprompt_1-_Iprompt_3, select(_IQ11_4 _IQ11_6 _IQ7_9 Q8 Q9) vce(robust)
est store H
***************************************************************************
***************************************************************************

*create weights
gen inc100nh = dp03_0059penh + dp03_0060penh + dp03_0061penh
label var inc100nh "Percent hholds income 100k and over"
gen q7100 = 0
replace q7100 = 1 if Q7 < 4
replace q7100 = 1 if Q7 == 5
replace q7100 = 1 if Q7 == 10
label var q7100 "Income 100k and over, 0-no 1-yes"

gen age45nh = ((((dp05_0012penh + dp05_0013penh + dp05_0014penh + dp05_0015penh ///
+ dp05_0016penh + dp05_0017penh)/100)*dp05_0001enh)/dp05_0087enh) * 100
label var age45nh "Citizen 18+ pop 45 and over, percent"
gen q945 = 0
replace q945 = 1 if Q9 > 2
label var q945 "Age 45 and over, 0-no 1-yes"

gen q4ur = Q4
replace q4ur = 4 if Q3==1

gen q11hs = 0
replace q11hs = 1 if Q11 < 6
label var q11hs "HS grad or higher, 0-no 1-yes"

ipfweight Q3 q4ur q7100 Q8 q945 Q10 q11hs, gen(wgt2) val(6.3 93.7 30.2 28.2 35.3 6.3 ///
63.8 36.2 71.3 28.7 39.4 60.6 50.8 49.2 6.9 93.1) maxit(25)

*weighted estimates
*Produce Table 3, model (2)
reg component _Iprompt_1-_Iprompt_3 [pw=wgt2], vce(robust)
est store Prew

esttab Preu Prew ///
using msgtabs.tex, se title("Messaging Experiment Results") ///
addnotes("All estimates use robust standard errors" ///
"Dependent variable - index of pro-housing attitudes") ///
star (* 0.10 ** 0.05 *** 0.01) tex mtitles("Unweighted" "Weighted") stats(N, label("Observations")) ///
label onecell append

esttab H ///
using appendtabs.tex, se title("Heckman Model of Messaging Experiment") ///
addnotes("Robust standard errors" ///
"Dependent variable - index of pro-housing attitudes") ///
star (* 0.10 ** 0.05 *** 0.01) tex stats(N, label("Observations")) ///
label onecell append

log close